package com.yanqu.road.server.cmd.activity.goddess;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.GoddessProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.goddess.GoddessConfig;
import com.yanqu.road.server.gameplayer.module.activity.goddess.GoddessModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.goddess.GoddessMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_GODDESS_COLOR_STONE_ROTATE, desc = "一键卸下")
public class GoddessColorStoneRotateCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {

        // 没有活动
        GoddessConfig config = GoddessMgr.getConfig();
        if (config == null || !ActivityMgr.activityInTime(config.getActivityInfo())) {
            ret = GameErrorCode.E_ACTIVITY_OVER_TIME;
            return;
        }

        GoddessProto.GoddessColorStoneRotateReqMsg reqMsg = GoddessProto.GoddessColorStoneRotateReqMsg.parseFrom(packet.getBytes());
        ret = player.getModule(GoddessModule.class).rotateStone(reqMsg.getStoneId());
    }

    @Override
    public void sendData(GamePlayer player) {

        if(ret != 0){
            player.sendPacket(Protocol.U_GODDESS_COLOR_STONE_ROTATE, GoddessProto.GoddessColorStoneRotateRespMsg.newBuilder().setRet(ret));
        }

    }
}
